#pragma once


 

namespace micro{
namespace gui{


class QAccelerator
{
	HACCEL m_hAccel;

public:

	QAccelerator(HACCEL hAccel = nullptr) : m_hAccel(hAccel)
	{
	}

	~QAccelerator(void)
	{
		if(m_hAccel != nullptr )
			::DestroyAcceleratorTable(m_hAccel);
	}


	QAccelerator & operator=(HACCEL hAccel)
	{
	  m_hAccel = hAccel;
	  return *this;
	}

	 void DestroyObject()
   {
      if( m_hAccel != nullptr ) {
         ::DestroyAcceleratorTable(m_hAccel);
         m_hAccel = nullptr;
      }
   }

   void Attach(HACCEL hAccel)
   {
      if(  m_hAccel != nullptr ) ::DestroyAcceleratorTable(m_hAccel);
      m_hAccel = hAccel;
   }  
   HACCEL Detach()
   {
      HACCEL hAccel = m_hAccel;
      m_hAccel = nullptr;
      return hAccel;
   }

   operator HACCEL() const { return m_hAccel; }

   bool IsNull() const { return m_hAccel == nullptr; }




   BOOL TranslateAccelerator(HWND hwnd, LPMSG pMsg)
   {
	   if(! m_hAccel )
		   return FALSE;
       
      return ::TranslateAccelerator(hwnd , m_hAccel, pMsg);
   }


   HACCEL LoadAccelerators(HINSTANCE h, LPCTSTR accel)
   {
      
      m_hAccel = ::LoadAccelerators( h /*global.GetInstance()*/, accel);
 
      return m_hAccel;
   }

};



}
 
}//micro